package com.zhengxing.jienci.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.annotation.JsonView;
import com.zhengxing.jienci.common.pojo.SocialUser;
import com.zhengxing.jienci.common.pojo.SysUser;
import com.zhengxing.jienci.common.support.SimpleResponse;
import com.zhengxing.jienci.user.service.UserService;
import com.zhengxing.jienci.web.context.SecurityContext;

/**
 * yyh
 */
@RestController
public class UserController {
	
	@Autowired
	private UserService userService;
	
	/**
	 * 
	 * @author yyh
	 * @Title: Userbinding
	 * @Description: 微信登录用户与手机用户绑定
	 * @param @param socialUser
	 * @param @return
	 * @return SimpleResponse
	 * @throws
	 */
	@PostMapping("/binding")
	public SimpleResponse Userbinding(SocialUser socialUser) {
		return userService.userbinding(socialUser);
	}
	
	/**
	 * 
	 * @author yyh
	 * @Title: getMyself
	 * @Description: 获取自己详情
	 * @param @return
	 * @return SysUser
	 * @throws
	 */
	@GetMapping("/myself")
	public SysUser getMyself() {
		String userId = SecurityContext.getUserId();
		return userService.getDetailUserById(userId);
	}
	
	/**
	 * 
	 * @author yyh
	 * @Title: getSysUser
	 * @Description: 获取用户详情
	 * @param @param userId
	 * @param @return
	 * @return SysUser
	 * @throws
	 */
	@GetMapping("/detail/{userId}")
	public SysUser getDetailSysUser(@PathVariable String userId) {
		return userService.getDetailUserById(userId);
	}
	
	/**
	 * 
	 * @author yyh
	 * @Title: getSimpleSysUser
	 * @Description: 
	 * @param @param userId
	 * @param @return
	 * @return SysUser
	 * @throws
	 */
	@JsonView(SysUser.SimpleView.class)
	@GetMapping("/simple/{userId}")
	public SysUser getSimpleSysUser(@PathVariable String userId) {
		return userService.getSimpleUserById(userId);
	}
	
	@JsonView(SysUser.SimpleView.class)
	@GetMapping("/simple/myself")
	public SysUser getSimpleMyself() {
		String userId = SecurityContext.getUserId();
		return userService.getSimpleUserById(userId);
	}
	
	
	/**
	 * 
	 * @author yyh
	 * @Title: follow
	 * @Description: 关注操作
	 * @param @param followId 关注人的id
	 * @param @return
	 * @return SimpleResponse
	 * @throws
	 */
	@PostMapping("/follow/{followId}")
	public SimpleResponse follow(@PathVariable String followId) {
		return userService.follow(followId);
	}
	
	/**
	 * 
	 * @author yyh
	 * @Title: isAttention
	 * @Description: 判断是否关注
	 * @param @param followId
	 * @param @return
	 * @return SimpleResponse
	 * @throws
	 */
	@GetMapping("/isAttention/{followId}")
	public SimpleResponse isAttention(@PathVariable String followId) {
		return userService.isAttention(followId);
	}
	
	@PostMapping("/update")
	public SimpleResponse updateUser(@RequestBody SysUser sysUser) {
		
		return null;
	}
	
}
